﻿using IronBefunge.Core;
using IronBefunge.Core.InstructionHandlers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Spackle;
using Spackle.Testing;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace IronBefunge.Core.Tests.InstructionHandlers
{
	[TestClass]
	public sealed class DuplicateInstructionHandlerTests : InstructionHandlerTests
	{
		[TestMethod]
		public void Handle()
		{
			var cells = new List<Cell>() { new Cell(new Point(0, 0), ':') };

			var stackCount = 0;

			InstructionHandlerTests.Run(new DuplicateInstructionHandler(), cells, (context) =>
				{
					context.Values.Push(33);
					stackCount = context.Values.Count;
				}, (context, result) =>
				{
					Assert.AreEqual(stackCount + 1, context.Values.Count);
					Assert.AreEqual(33, context.Values.Pop());
					Assert.AreEqual(33, context.Values.Pop());
				});
		}

		[TestMethod]
		public void HandleWithEmptyStack()
		{
			var cells = new List<Cell>() { new Cell(new Point(0, 0), ':') };

			var stackCount = 0;

			InstructionHandlerTests.Run(new DuplicateInstructionHandler(), cells, (context) =>
				{
					stackCount = context.Values.Count;
				}, (context, result) =>
				{
					Assert.AreEqual(stackCount + 2, context.Values.Count);
					Assert.AreEqual(0, context.Values.Pop());
					Assert.AreEqual(0, context.Values.Pop());
				});
		}
	}
}
